package com.cc.openeye.dynamic.recommend.items.dynamic

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import assest.common.collect
import com.cc.openeye.borderRadius
import com.cc.openeye.dynamic.recommend.entity.dynamicResponse.Data
import com.cc.openeye.height
import com.cc.openeye.margin
import com.cc.openeye.width
import com.tencent.kuikly.compose.coil3.rememberAsyncImagePainter
import com.tencent.kuikly.compose.foundation.Image
import com.tencent.kuikly.compose.foundation.layout.Box
import com.tencent.kuikly.compose.foundation.layout.BoxWithConstraints
import com.tencent.kuikly.compose.foundation.layout.Column
import com.tencent.kuikly.compose.foundation.layout.Row
import com.tencent.kuikly.compose.foundation.layout.fillMaxWidth
import com.tencent.kuikly.compose.foundation.layout.padding
import com.tencent.kuikly.compose.foundation.shape.CircleShape
import com.tencent.kuikly.compose.material3.Text
import com.tencent.kuikly.compose.resources.painterResource
import com.tencent.kuikly.compose.ui.Alignment
import com.tencent.kuikly.compose.ui.Modifier
import com.tencent.kuikly.compose.ui.draw.clip
import com.tencent.kuikly.compose.ui.graphics.Color
import com.tencent.kuikly.compose.ui.layout.ContentScale
import com.tencent.kuikly.compose.ui.platform.LocalActivity
import com.tencent.kuikly.compose.ui.unit.dp
import com.tencent.kuikly.compose.ui.unit.sp

@Composable
fun DynamicItem(data: Data) {

    val pageViewWidth = LocalActivity.current.getPager().pageData.pageViewWidth

    val width = remember {
        (pageViewWidth - 30 - 8) / 2
    }

    Column(modifier = Modifier.fillMaxWidth()) {
        BoxWithConstraints(
            modifier = Modifier.fillMaxWidth(),
            contentAlignment = Alignment.TopEnd
        ) {
            Image(
                modifier = Modifier.fillMaxWidth().height(data.getHeight(width))
                    .borderRadius(5.dp),
                painter = rememberAsyncImagePainter(data.getImage()),
                contentDescription = "",
            )
        }

        Text(
            data.content?.data?.description ?: "",
            color = Color(0xFF333333),
            fontSize = 13.sp,
            modifier = Modifier.padding(top = 5.dp)
        )


        Box(
            contentAlignment = Alignment.CenterStart,
            modifier = Modifier.padding(top = 5.dp).fillMaxWidth()
        ) {
            Row(verticalAlignment = Alignment.CenterVertically) {
                Image(
                    painter = rememberAsyncImagePainter(data.content?.data?.owner?.avatar ?: ""),
                    contentDescription = "",
                    modifier = Modifier.width(25F).height(25F).clip(CircleShape),
                )

                Text(
                    data.content?.data?.owner?.nickname ?: "",
                    color = Color(0xFF333333),
                    fontSize = 11.sp,
                    modifier = Modifier.margin(start = 2f)
                )
            }

            Row(
                modifier = Modifier.align(Alignment.CenterEnd),
                verticalAlignment = Alignment.CenterVertically
            ) {

                Image(
                    painter = painterResource(collect),
                    contentDescription = "",
                    modifier = Modifier.width(15f).height(15f),
                    contentScale = ContentScale.FillBounds
                )

                Text(
                    (data.content?.data?.consumption?.collectionCount ?: 0).toString(),
                    color = Color(0xFF333333),
                    fontSize = 11.sp,
                    modifier = Modifier.margin(start = 2f)
                )
            }
        }


    }
}